package com.chen.q2;


import com.chen.q2.fibo.FiboAdderCallable;

import java.util.concurrent.*;

/**
 * Future+ExecutorService
 */
public class Approach10 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        // 在这里创建一个线程或线程池，
        // 异步执行 下面方法
        ExecutorService executor = Executors.newSingleThreadExecutor();
        FiboAdderCallable fiboAdder = new FiboAdderCallable(36);
        Future<Integer> future = executor.submit(fiboAdder);

        try {
            int result = future.get();
            // 确保  拿到result 并输出
            System.out.println("异步计算结果为：" + result);

            System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.exit(1);

    }
}
